package com.ruix.app.model;

import android.text.TextUtils;

import com.ruix.app.util.LogUitl;

import org.json.JSONObject;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * Created by hadexs on 2017/5/1.
 */

public class ClassDetail implements Serializable {

    private String classId; //班级id
    private String encryptId;//圈子加密ID
    private String name;//圈子名
    private String icon;//圈子logo
    private String organization;//机构
    private String banner;//圈子banner
    private String suitable;//适合对象
    private String benifite;//课程收益
    private String course;//课程状况
    private String mentorIntro;//导师介绍
    private String classService;//班级信息
    private boolean isFirstOpenCircle; //第一次打开圈子
    private String role;//在班级中的角色

    private boolean canSharePost;//是否可以分享
    private String shareUrl;
    private long openTime; //开班时间
    private long completeTime; //结业时间
    private String organizLogo; //班级logo

    private boolean newCourse; //行课程
    private boolean newNotice; //新通知
    private boolean prohibited; //是否被禁言
//    private ClassOwner classOwner; //
    private String classOwnerName;//班级所有者信息

    private String status;  //1为开班了，2为进行中,3为结业
    private String type;   //圈子类型  1为班级圈 2 师友圈

    public ClassDetail parse(JSONObject object) {
        if (object != null) {
            setEncryptId(object.optString("encrypt_id", ""));
            setName(object.optString("name", ""));
            setIcon(object.optString("icon", ""));
            setBanner(object.optString("banner", ""));
            setSuitable(object.optString("suitable", ""));
            setBenifite(object.optString("benifite", ""));
            setCourse(object.optString("course", ""));
            setMentorIntro(object.optString("mentor_intro", ""));
            setClassService(object.optString("class_service", ""));
            setCanSharePost(object.optInt("share", 0) == 1);
            setOpenTime(object.optLong("open_at", 0) * 1000);
            setCompleteTime(object.optLong("close_at", 0) * 1000);
            setNewCourse(object.optInt("new_course", 0) >= 1);
            setNewNotice(object.optInt("new_notice", 0) >= 1);
            setType(object.optString("type", ""));
            setStatus(object.optString("status", ""));

            JSONObject organization = object.optJSONObject("organization");
            if (organization != null) {
                setOrganization(organization.optString("name", ""));
                setOrganizLogo(organization.optString("logo", ""));
            }


        }
        return this;
    }


    public String getEncryptId() {
        if (!TextUtils.isEmpty(encryptId)){
            try {
                return URLEncoder.encode(encryptId,"utf-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        return encryptId;
    }

    public void setEncryptId(String encryptId) {
        this.encryptId = encryptId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getOrganization() {
        if (organization != null){
            return organization;
        }
        return "";
    }

    public void setOrganization(String organization) {
        this.organization = organization;
    }

    public String getBanner() {
        return banner;
    }

    public void setBanner(String banner) {
        this.banner = banner;
    }

    public String getSuitable() {
        return suitable;
    }

    public void setSuitable(String suitable) {
        this.suitable = suitable;
    }

    public String getBenifite() {
        return benifite;
    }

    public void setBenifite(String benifite) {
        this.benifite = benifite;
    }

    public String getCourse() {
        return course;
    }

    public void setCourse(String course) {
        this.course = course;
    }

    public String getMentorIntro() {
        return mentorIntro;
    }

    public void setMentorIntro(String mentorIntro) {
        this.mentorIntro = mentorIntro;
    }

    public String getClassService() {
        return classService;
    }

    public void setClassService(String classService) {
        this.classService = classService;
    }

    public boolean isCanSharePost() {
        return canSharePost;
    }

    public void setCanSharePost(boolean canSharePost) {
        this.canSharePost = canSharePost;
    }

    public String getShareUrl() {
        return shareUrl;
    }

    public void setShareUrl(String shareUrl) {
        this.shareUrl = shareUrl;
    }

    public String getClassId() {
        return classId;
    }

    public void setClassId(String classId) {
        this.classId = classId;
    }

    public String getClassStatus() {
        if ("1".equals(status)) {
            return "开班了";
        } else if ("2".equals(status)) {
            return "进行中";
        } else if ("3".equals(status)) {
            return "结业";
        }
        return "开班了";
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public long getOpenTime() {
        return openTime;
    }

    public void setOpenTime(long openTime) {
        this.openTime = openTime;
    }

    public long getCompleteTime() {
        return completeTime;
    }

    public void setCompleteTime(long completeTime) {
        this.completeTime = completeTime;
    }


    public String getOrganizLogo() {
        return organizLogo;
    }

    public void setOrganizLogo(String organizLogo) {
        this.organizLogo = organizLogo;
    }

    public boolean isNewCourse() {
        return newCourse;
    }

    public void setNewCourse(boolean newCourse) {
        this.newCourse = newCourse;
    }

    public boolean isNewNotice() {
        return newNotice;
    }

    public void setNewNotice(boolean newNotice) {
        this.newNotice = newNotice;
    }

    public boolean isProhibited() {
        return prohibited;
    }

    public void setProhibited(boolean prohibited) {
        this.prohibited = prohibited;
    }

    public boolean isFirstOpenCircle() {
        return isFirstOpenCircle;
    }

    public void setFirstOpenCircle(boolean firstOpenCircle) {
        isFirstOpenCircle = firstOpenCircle;
    }

    public String getClassOwnerName() {
        return classOwnerName;
    }

    public void setClassOwnerName(String classOwnerName) {
        this.classOwnerName = classOwnerName;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    //室友圈
    public boolean isTeacherFriendCircle(){
        return "2".equals(type);
    }

    @Override
    public String toString() {
        return "ClassDetail{" +
                "classId='" + classId + '\'' +
                ", encryptId='" + encryptId + '\'' +
                ", name='" + name + '\'' +
                ", icon='" + icon + '\'' +
                ", organization='" + organization + '\'' +
                ", banner='" + banner + '\'' +
                ", suitable='" + suitable + '\'' +
                ", benifite='" + benifite + '\'' +
                ", course='" + course + '\'' +
                ", mentorIntro='" + mentorIntro + '\'' +
                ", classService='" + classService + '\'' +
                ", canSharePost=" + canSharePost +
                ", shareUrl='" + shareUrl + '\'' +
                '}';
    }
}
